package com.onemore.task.model;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.voovan.tools.log.Logger;

import com.alibaba.fastjson.JSONObject;
import com.onemore.task.JdbcGlobal;

public class ModelSpthd extends JdbcGlobal{
    final static private String spthd_field[] = new String[] {"DJBH","RQ","YDJH",
    		"DJXZ","FPLX","LXDJ","DM1","DM2","DM2_1","DM4","QDDM","QYDM","YGDM",
    		"SL","JE","BZJE","TJ","XC","YS","JZ","JZRQ","JS","SH","SHRQ","SP",
    		"SPRQ","LL","ZDR","JZR","SHR","SPR","LLR","YXRQ","RQ_1","RQ_2","RQ_4",
    		"BZ","BYZD1","BYZD2","BYZD3","BYZD4","BYZD5","BYZD6","BYZD9","BYZD10","BYZD11",
    		"BYZD12","ZS","ZSR","ZSRQ","DM5","DM6","DM6_1","BYZD16","BYZD17","BYZD18"};
    static public void createTrigger() throws SQLException
	{
		String sql="CREATE TRIGGER [dbo].[onemore_spthd] ON [dbo].[SPTHD] AFTER INSERT, UPDATE, DELETE AS BEGIN DECLARE @strAction varchar(10) IF EXISTS(SELECT 1 FROM inserted) AND NOT EXISTS(SELECT 1 FROM deleted) SET @strAction = 'insert' IF EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted) SET @strAction = 'update' IF NOT EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted) SET @strAction = 'delete' declare @KEY_VALUE varchar(50); IF @strAction != 'delete' select @KEY_VALUE=DJBH from inserted where SH=1 and DM2 like '20%'; insert into ONE_MTAB (KEY_VALUE,TAB_NAME,ACT_TYPE) values(@KEY_VALUE,'SPTHD',@strAction); END";
		getJdbcOperate().update(sql);
	}
	/**
	 * 从数据库获取进货单数据
	 * @param DJBH
	 * @return
	 * @throws SQLException
	 */
    static public List<Map<String, Object>> getList(String DJBH) throws SQLException
    {
    	String sql = "";
        //查询测试
        sql = "select * from SPTHD where DJBH='"+DJBH+"'";
    	if(DJBH == null || DJBH =="") {
            Logger.error(sql);
    	}
        List<Map<String, Object>> manyMaps = null;
		manyMaps = getJdbcOperate().queryMapList(sql);
		return manyMaps;
    }
    /*static public List<Map<String, Object>> getNotUpedList() throws SQLException
    {
    	String sql = "";
        //查询测试
        sql = "select * from SPTHD where IFUP IS NULL";
        List<Map<String, Object>> manyMaps = null;
		manyMaps = getJdbcOperate().queryMapList(sql);
		return manyMaps;
    }*/

    /*static public boolean updateFlag(String DJBH) throws SQLException
    {
        //查询测试
    	return updateDate("SPTHD", "DJBH='"+DJBH+"'", "IFUP=1");
    }*/
}
